// 测试设置文件
import { vi } from 'vitest'

// 模拟localStorage
const localStorageMock = (() => {
  let store = {}
  return {
    getItem: vi.fn((key) => store[key] || null),
    setItem: vi.fn((key, value) => {
      store[key] = value.toString()
    }),
    removeItem: vi.fn((key) => {
      delete store[key]
    }),
    clear: vi.fn(() => {
      store = {}
    })
  }
})();

// 设置全局模拟
Object.defineProperty(window, 'localStorage', {
  value: localStorageMock
})

// 重置所有模拟
global.beforeEach(() => {
  vi.resetAllMocks()
})